﻿using System;
using ContractManagementSystem.BusinessLogic;
using ContractManagementSystem.Entity;
using System.Globalization;

namespace ContractManagementSystem.Controls
{
    public partial class AddConsultant : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Submit.OnClientClick = "return ValidateConsultant();";
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            var consultantEntity = new ConsultantEntity
                                       {
                                           UserId = UserBusiness.InitialUser(FullNameTextBox.Text, "Consultant"),
                                           Birthday = DateTime.Parse(BirthDateTextBox.Text,CultureInfo.CurrentCulture),
                                           FullName = FullNameTextBox.Text,
                                           Gender = GenderDropDownList.SelectedIndex,
                                           Email = EmailTextBox.Text,
                                           PhoneNumber = PhoneNumberTextBox.Text
                                       };
            if(ConsultantBusiness.Insert(consultantEntity))
            {
                MessageLabel.Text = "Insert Success !";
                Response.Redirect("ViewAllConsultant.aspx");
            }
            else
            {
                MessageLabel.Text = "Insert False !";
            }
        }
    }
}